import 'package:app/common/colors.dart';
import 'package:app/services/address.dart';
import 'package:app/utils/hexcolor.dart';
import 'package:app/utils/persisten_storage.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'serve_setting_page.dart';

class MineOnePage extends StatefulWidget {
  @override
  _MineOnePageState createState() => _MineOnePageState();
}

class _MineOnePageState extends State<MineOnePage> {
//授权页登录业务逻辑添加
  String login_name = "";
  String login_mobile = "";
  String login_acctoken = "";
  String login_image_128 = "";

  @override
  void initState() {
    super.initState();
    print("MineOnePage==initState>>");
    getInitData();
  }

  void getInitData() async {
    print("getInitData==print>>");
    SharedPreferences prefs = await SharedPreferences.getInstance();
    login_name = prefs.getString("name")!;
    login_mobile = prefs.getString("login_mobile")!;
    login_image_128 = prefs.getString("image128")!;
    print("login_name==$login_name>>");
    print("login_mobile==$login_mobile>>");
    if (login_image_128.startsWith("http")) {
      print("login_image_128==$login_image_128>>");
    } else {
      login_image_128 = Address.homeHost + login_image_128;
      print("login_image_128==$login_image_128>>");
    }
    setState(() {

    });
  }

  List menuTitles = [
    '实名认证',
    '定位',
    '账号安全',
    '帮助与反馈',
    '关于',
    '通用',
  ];
  List menuIcons = [
    "images/mine_icons0.png",
    "images/mine_icons1.png",
    "images/mine_icons2.png",
    "images/mine_icons3.png",
    "images/mine_icons4.png",
    "images/mine_icons5.png",
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView.separated(
          itemBuilder: (context, index) {
            if (index == 0) {
              return Column(
                children: [
                  Padding(
                      padding: const EdgeInsets.all(8),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Container(
                            margin: const EdgeInsets.only(left: 12),
                            child: const Text(
                              '我的',
                              style: TextStyle(
                                  fontSize: 20, fontWeight: FontWeight.bold),
                            ),
                          ),
                          IconButton(
                            icon: Image.asset("images/mine_replace.png"),
                            onPressed: () {
                              // 修改 state 内部变量, 且需要界面内容更新, 需要使用 setState()
                              setState(() {});
                            },
                          )
                        ],
                      )),
                  Padding(
                      padding: const EdgeInsets.all(8),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Row(
                            children: [
                              Container(
                                height: 100,
                                margin: const EdgeInsets.all(12),
                                child: Container(
                                    margin: const EdgeInsets.all(10),
                                    width: 72,
                                    height: 72,
                                    decoration: BoxDecoration(
                                        borderRadius:
                                            BorderRadius.circular(6.0),
                                        image: DecorationImage(
                                          image: NetworkImage(login_image_128!),
                                        ))),
                              ),
                              Container(
                                  height: 72,
                                  child: Column(
                                    mainAxisAlignment:
                                        MainAxisAlignment.spaceAround,
                                    crossAxisAlignment:
                                        CrossAxisAlignment.start,
                                    children: [
                                      Text(login_name),
                                      Text(login_mobile)
                                    ],
                                  )),
                            ],
                          ),
                          Container(
                            child: const Icon(
                              Icons.arrow_forward_ios,
                              size: 15,
                            ),
                          ),
                        ],
                      ))
                ],
              );
            }
            index -= 1;
            return
              GestureDetector(
                  onTap: () {
                    print("index==>>>$index==>>");
                    if(index==5){
                      Get.to(ServeSettingPage());
                    }
                  },
                  child:Container(
                      child: ListTile(
                        leading: Image.asset(menuIcons[index], width: 32, height: 32),
                        //左图标
                        title: Text(
                          menuTitles[index],
                          style: const TextStyle(fontSize: 16),
                        ),
                        //中间标题
                        trailing: const Icon(
                          Icons.arrow_forward_ios,
                          size: 15,
                        ),
                      )
                  )
              );
          },
          separatorBuilder: (context, index) {
            return (index == 0 || index == 3)
                ? const Divider(thickness: 16, color: Color(0xFFEEEEEE))
                : const Divider(indent: 20, endIndent: 20);
          }, //分隔线
          itemCount: menuTitles.length + 1),
    );
  }
}
